package com.atqh.srrt.chicken.controller;

import com.atqh.srrt.chicken.Multithreading.UserThreadLocal;
import com.atqh.srrt.chicken.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redisTest")
@CrossOrigin
public class RedisTestController {
    //测试redis连通接口，拦截器，线程池接口
    @Autowired(required = false)
    private RedisTemplate redisTemplate;

    @GetMapping
    public String testRedis() {
        SysUser sysUser = UserThreadLocal.get();
        System.out.println(sysUser);
        //设置值到redis
        redisTemplate.opsForValue().set("name1", "lucy1");
        //从redis获取值
        String name = (String) redisTemplate.opsForValue().get("name1");
        System.out.println(name);
        return name;
    }
}